ShowTable of Contents
Overview
The IBM® Sametime® Connect client allows users to make telephone calls via IBM Sametime Unified Telephony (SUT). This functionality can be called from a browser, allowing its integration directly into the browser's default functionality. This article shows how to create such an extension and how to install it into Internet Explorer.
This extenson adds a new menu item to the Internet Explorer context menu. After installing, when you highlight a phone number on a web page, you can right-click on the highlighted area and select the “Phone” item. The number will then be called using Sametime Unified Telephony functions in your Sametime client.
Installation and removal
To install the extension is quite simple. Download the attached zip file, and extract its contents. Then run the i
nstall.bat batch file, either from the command line or by double-clicking from Windows Explorer. When the process is complete the batch file will wait for you to press Enter to allow it to finish. The functionality will become available when you next start Internet Explorer.
Removing the extension is equally straightforward. Run the uninstall.bat file, again either from the command line or by double-clicking. When the process is complete the batch file will wait for you to press Enter to allow it to finish. If Internet Explorer is running, the uninstall process will not be complete until you next exit the browser.
How does it work?
There are two parts to the extension. The first is to tell Internet Explorer where it should find the code, and this is done by adding a new key to the Microsoft Windows registry, along with two parameters. This can be seen in the
install.reg file:
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Phone]
@="C:\\Program Files\\Internet Explorer\\Plugins\\SUTPhone.htm"
"Contexts"=dword:00000010
Here we add the
Phone key to the
MenuExt set of keys for Internet Explorer, and we tell it the location of the code file. Additionally, the
Contexts parameter is set to the value
0x10 to indicate that this extension should be executed for hightlighted text in a web page.
The code itself is simply an HTML file with a single JavaScript which is the code executed when the menuitem
Phone is clicked. The first thing it does is pick up the text that is highlighted:
Listing 1: Extract the highlighted string
var parentwin = external.menuArguments;
var doc = parentwin.document;
var sel = doc.selection;
var rng = sel.createRange();
var str = new String(rng.text);
Once we have the string, in our example code we use pattern-matching to reformat the string into an all-numeric value that can be dialled. The example even replaces an initial “+” with the US international dial code of “011” which means that if this sample is used in other countries, the dial code should be changed as appropriate, e.g. to “00” in Europe. Note that this is not necessary: SUT is quite capable of extracting a number correctly without this manipulation.
Listing 2: Reformat the selected string into a numeric value
var phoneRegex = /^[\s]*((\+|00|011)[-\s]*[\d]{1,3}[-\s]*)?(\(\d{1,4}\)[-\s]*)?([\d\s]{1,14})$/;
// This function generates a phone number which contains only digits
function validateNum(str) {
// Apply the regex
var num = phoneRegex.exec(str);
if (!num) // No match!
return null;
// 1=Intl code, 2=Intl prefix, 3=area code, 4=number
if (num[1] && num[2]) {
// This replaces “+” with US dial
num[1] = num[1].replace(num[2], "011").replace(/ /g, "");
} else {
num[1] = "";
}
if (num[3]) {
num[3] = num[3].replace("(0)","").replace(/[() ]/g,"");
} else {
num[3] = "";
}
num[4] = num[4].replace(/ /g,"");
return num[1] + num[3] + num[4];
}
Finally, if the string is identified as being a phone number, it passes it to SUT. We use a trick here to allow JavaScript to run without causing any cross-domain issues. The URL of the REST API in the Sametime Connect client is used as the src= parameter of an HTML image, causing that address to be called, resulting in the SUT API being executed and the call is placed as required.
Listing 3: Making the call
Requirements
There are a number of requirements for the extension to function as required:
-
You must have administrator rights to install or uninstall the plugin. Also, you must run install/uninstall from the directory where you extracted the files.
-
You must have the Sametime Connect client running and be logged in to Sametime.
-
You must have SUT installed and configured correctly.
-
You must enable access to the WebConnect API in the Sametime client.
-
This only works with Internet Explorer 8 or later.
The Sametime Connect Web API may be disabled by default. To see the current state of each function, login to Sametime and go to http://localhost:59449/stwebapi/listservices in your browser. Functions that are disabled can be enabled by adding a preference to the file plugin_customization.ini in {Notes Install Directory}\framework\rcp if using the embedded client, or {Sametime Install Directory}\rcp if you have the Sametime Connect client, using the following format:
com.ibm.collaboration.realtime.webapi.Enabled=true
For example, to enable the call function you would add this preference:
com.ibm.collaboration.realtime.webapi.callEnabled=true
To enable all Web API functions you can use the global override:
com.ibm.collaboration.realtime.webapi/enableAllWebApisOverride=true
Conclusion
When browsing the web, you can now make a phone call to a number which is on any web page with very little effort, enhacing your browsing experience by improved integration of Sametime into Internet Explorer.
Download
Sample code discussed here is attached to the article. Expand the "Attachments" section below to download the zip file.
Resources
• developerWorks® IBM Sametime product page:
• http://www.ibm.com/developerworks/lotus/products/instantmessaging/
• Community article “Firefox Plugin for Click to Call”:
• http://www-10.lotus.com/ldd/stwiki.nsf/dx/Firefox_Plugin_for_Click_to_Call
• MSDN article “Creating Add-ons for Internet Explorer: Customizing Menus”:
• http://msdn.microsoft.com/en-us/library/bb735853%28v=vs.85%29.aspx
About the author
Brendan Murray joined Lotus Development in 1991 and was acquired, along with the rest of the company, by IBM in 1995. Most recently he has been working on Sametime with a particular emphasis on its Web functionality. You can reach him at brendan_murray@ie.ibm.com.